package cn.yunyichina.provider.iface.entity.common;

import java.io.Serializable;

/**
 * Created by Lullaby on 2016/10/14.
 */
public class ResCommon<T> implements Serializable {

    public static final String SUCCESS_CODE = "0";

    public static final String SUCCESS_MESSAGE = "success";

    private String resultCode;

    private String resultMessage;

    private T result;

    public ResCommon() {
        super();
        this.resultCode = SUCCESS_CODE;
        this.resultMessage = SUCCESS_MESSAGE;
    }

    public ResCommon(String resultCode, String resultMessage) {
        super();
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
    }

    public ResCommon(String resultCode, String resultMessage, T result) {
        super();
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
        this.result = result;
    }

    public void setResultCodeAndMessage(String resultCode, String resultMessage) {
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
    }

    public ResCommon<T> buildResultCodeAndMessage(String resultCode, String resultMessage) {
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
        return this;
    }

    public void setResultCodeAndMessageAndResult(String resultCode, String resultMessage, T result) {
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
        this.result = result;
    }

    public ResCommon<T> buildResultCodeAndMessageAndResult(String resultCode, String resultMessage, T result) {
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
        this.result = result;
        return this;
    }

    public String getResultCode() {
        return resultCode;
    }

    public String getResultMessage() {
        return resultMessage;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public ResCommon<T> buildResult(T result) {
        this.result = result;
        return this;
    }

    public boolean isSuccess() {
        return ResCommon.SUCCESS_CODE.equals(this.getResultCode());
    }

}
